#ifndef EXPORTUISTATESYNCHRONIZER_H
#define EXPORTUISTATESYNCHRONIZER_H

#include <QObject>
#include <QPushButton>
#include <QProgressBar>
#include <QLabel>
#include <QPropertyAnimation>
#include <QEasingCurve>
#include <QTimer>
#include "unifiedexportstatemanager.h"

/**
 * ExportUIStateSynchronizer - 导出UI状态同步器
 * 
 * 负责将统一导出状态管理器的状态变化同步到UI组件
 * 提供动画效果、状态反馈和用户交互处理
 */
class ExportUIStateSynchronizer : public QObject
{
    Q_OBJECT

public:
    explicit ExportUIStateSynchronizer(UnifiedExportStateManager* stateManager, 
                                     QPushButton* exportButton,
                                     QProgressBar* progressBar,
                                     QLabel* statusLabel,
                                     QObject* parent = nullptr);
    
    // 配置方法
    void setAnimationEnabled(bool enabled);
    void setTooltipEnabled(bool enabled);
    void setCompletionDelay(int delayMs);
    
    // 状态查询
    bool isAnimationEnabled() const { return m_animationEnabled; }
    bool isTooltipEnabled() const { return m_tooltipEnabled; }

private slots:
    // 状态变化处理
    void onStateChanged(UnifiedExportStateManager::ExportState newState, 
                       UnifiedExportStateManager::ExportState oldState);
    void onFileStateChanged(UnifiedExportStateManager::FileState newState);
    void onContextChanged(const UnifiedExportStateManager::ExportContext& context);
    void onProgressChanged(int completed, int total, const QString& status);
    
    // 动画处理
    void onExportingAnimationFinished();
    void onCompletionAnimationFinished();
    void onErrorAnimationFinished();

private:
    // UI更新方法
    void updateExportButton();
    void updateProgressBar();
    void updateStatusLabel();
    void updateTooltips();
    
    // 动画方法
    void startExportingAnimation();
    void startCompletionAnimation();
    void startErrorAnimation();
    void stopAllAnimations();
    
    // 样式方法
    QString getButtonStyle(UnifiedExportStateManager::ExportState state) const;
    QString getProgressBarStyle() const;
    QString getStatusLabelStyle() const;
    
    // 工具提示方法
    QString getButtonTooltip(UnifiedExportStateManager::ExportState state) const;
    QString getProgressTooltip(int completed, int total) const;
    QString getStatusTooltip(const QString& status) const;

private:
    // 状态管理器引用
    UnifiedExportStateManager* m_stateManager;
    
    // UI组件引用（不拥有所有权）
    QPushButton* m_exportButton;
    QProgressBar* m_progressBar;
    QLabel* m_statusLabel;
    
    // 配置
    bool m_animationEnabled = true;
    bool m_tooltipEnabled = true;
    int m_completionDelayMs = 2000;
    
    // 动画
    QPropertyAnimation* m_buttonAnimation;
    QPropertyAnimation* m_progressAnimation;
    QPropertyAnimation* m_statusAnimation;
    QTimer* m_completionTimer;
    
    // 状态跟踪
    UnifiedExportStateManager::ExportState m_currentState = UnifiedExportStateManager::ExportState::Idle;
    UnifiedExportStateManager::FileState m_currentFileState = UnifiedExportStateManager::FileState::NoFiles;
    UnifiedExportStateManager::ExportContext m_currentContext;
};

#endif // EXPORTUISTATESYNCHRONIZER_H
